<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>问题列表</title>
<link href="<%=path%>/static/usercss/css/all.css?ehwee333e43" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<%=path%>/static/js/jquery-3.2.1.js"></script>
<jsp:include page="/WEB-INF/web/includ/header.jsp"></jsp:include>
<c:set var="pageNum" value="${requestScope.pager.pageNo}"></c:set>
<!--[if IE]>
<script>
(function(){if(!/*@cc_on!@*/0)return;var e = "abbr,article,aside,audio,canvas,datalist,details,dialog,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(','),i=e.length;while(i--){document.createElement(e[i])}})()
</script>
<![endif]-->
</head>
<body>
<section>
<div class="wrap">
  <div id="seach">
    <div id="logo" class="qanda"><a href="http://fenlicx.qinglab.cn" title="垃圾分类问答">垃圾分类问答</a></div>
    <div class="qanda">
      <input type="text" name="seach" value="${param.keyword }" class="seach_txt" id="seach" aria-label="输入搜索问题" placeholder="输入搜索问题">
      <input id="seachBySolr" type="submit" class="seach_bun" name="button" id="button" value="搜问答">
      <a href="<%=path%>/web/question/addQ"><input type="button" class="seach_bun" name="button" id="button" value="提问题"></a>
      <%-- <c:if test="${userinfo.id}"!=null ></c:if> --%>
    </div>
  </div>
<nav>
    <div class="seach">
    <form action="<%=path %>/web/question/chaXun" method="post">
    <select name="firstType" id="firstType">
    <option>全部</option>
         <c:forEach items="${requestScope.firsttypes}" var="firsttype">
		 <option value="${firsttype.id}">${firsttype.title }</option>
		 </c:forEach>
    </select>
    <select name="secondType" id="secondType">
         <c:forEach items="${requestScope.secondtypes}" var="secondtype">
		 <option value="${secondtype.id}">${secondtype.title }</option>
		 </c:forEach>
    </select>
    <select name="rubbishId" id="rubbish">
    <option>全部</option>
         <c:forEach items="${requestScope.rubbishs}" var="rubbish">
		 <option value="${rubbish.id}">${rubbish.name }</option>
		 </c:forEach>
    </select>
   <input type="submit" name="submit" id="submit" value="查看分类">
   
    </form>
  </div>
</nav>
<article class="article">
  <div class="title">
    <h1>全部问答</h1>
    <%-- <a href="<%=path %>/web/question/list">时间排序</a>
    <a href="<%=path %>/web/reDu">热度排序</a> --%>
   <!--  <a href="#">智能排序？</a> -->
  </div>
  <ul>
    
    <c:forEach items="${requestScope.questions}" var="question">
	<li> <h3><a href="<%=path %>/web/question/questionSingle?id=${question.id}">${question.content}</a></h3>
      <span>提问者：${question.userinfo.nickName }</span>
      <span>答复数：${question.replyCount }</span>
      <p>${question.content}</p>
      </li>
      </c:forEach>
     <c:if test="${requestScope.questions[0] eq null}">
    暂时没有查出相关问题。。您可以<a style="color:blue;" href="<%=path %>/web/question/addQ">添加一个</a>
    </c:if>
    
  </ul>
  
  <div class="pagination">
     <a id="first" href="<%=path %>/web/seachQuestion?keyword=${param.keyword }&pageNo=1">首页</a>
    <a id="prev" href="javaScript:void(0)" class="number">上一页</a>
    <c:forEach begin="1" end="${pager.pageCount }" var="page">
    	<a style="border:1px solid #ddd" id="page${page }" href="<%=path %>/web/seachQuestion?keyword=${param.keyword }&pageNo=${page}" class="number">${page}</a>
    </c:forEach>
    <a id="next" href="javaScript:void(0)" class="number">下一页</a>
    <a id="last" href="<%=path %>/web/seachQuestion?keyword=${param.keyword }&pageNo=${requestScope.pager.pageCount}">尾页</a>
    <span>共${requestScope.pager.pageCount}页</span>&nbsp;&nbsp;
	<span>共&nbsp;${requestScope.pager.dataCount}&nbsp;篇文章</span>
  </div>
</article>
</div>
</section>
<footer>
  <jsp:include page="/WEB-INF/web/includ/footer.jsp"></jsp:include>
</footer>
</body>

	<script type="text/javascript">
	
		$(function() {
			$("#page${requestScope.pager.pageNo}").css("background-color","#666");
			$("#page${requestScope.pager.pageNo}").css("color","#fff");
			
		  initSecondType(); 
			//给二级分类添加change事件
			$("#firstType").change(initSecondType);
			//给垃圾添加change事件
			$("#secondType").change(initRubbish);
		});
		
		function initSecondType() {
			
				var firstTypeId = $("#firstType").val();
				$("#secondType").empty();
				$("#secondType").append("<option>全部</option>");
		$.ajax({
					type : "POST",
					url : "<%=path%>/web/question/findAllByFirstTypeId",
					data : "firstTypeId="+firstTypeId,
					dataType:"json",
					success : function(secondtypes) {
					 for(var i=0;i<secondtypes.length;i++)
					 {
					 	$("#secondType").append("<option value=\""+secondtypes[i].id+"\">"+secondtypes[i].title+"</option>");
					 	
					 }	
					 
					//初始化三級
					 initRubbish(); 
						
					}
				}); 
			}
	
		function initRubbish() {
			
			var secondTypeId = $("#secondType").val();
			$("#rubbish").empty();
			$("#rubbish").append("<option>全部</option>");
	$.ajax({
				type : "POST",
				url : "<%=path%>/web/question/findAllBySecondTypeId",
				data : "secondTypeId="+secondTypeId,
				dataType:"json",
				success : function(rubbishs) {
				 for(var i=0;i<rubbishs.length;i++)
				 {
				 	$("#rubbish").append("<option value=\""+rubbishs[i].id+"\">"+rubbishs[i].name+"</option>");
				 }						
				}
			}); 
		} 
	
		$(function() {
			
			/*上一页，下一页*/
			  $("#prev").click(function(){
				if(${requestScope.pager.pageNo}<=1){
					$(this).attr("href","javaScript:void(0)");
				}else{
					$(this).attr("href","<%=path%>/web/seachQuestion?keyword=${param.keyword }&pageNo=${requestScope.pager.pageNo-1}");
				}
			});
			
			$("#next").click(function(){
				if(${requestScope.pager.pageNo}>=${requestScope.pager.pageCount}){
					$(this).attr("href","javaScript:void(0)"); 
				}else{
					$(this).attr("href","<%=path%>/web/seachQuestion?keyword=${param.keyword }&pageNo=${requestScope.pager.pageNo+1}");
				}
			}); 
			
		})
		
		$(function() {
			$("#seachBySolr").click(function() {
			var keyword = $(this).prev().val();
			location.href="<%=path %>/web/seachQuestion?keyword="+keyword;  
		})
	})
</script>
</html>

